package com.itheima.response;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/demo11")
public class ServletDemo11 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //response字符流默认码表是iso-8859-1,这个码表是不支持中文的，所以在进行编码是，就已经乱码了
        //要解决字符流输出中文乱码问题，需要1。设置响应体的编码字符集2.设置浏览器的解码字符集
        resp.setCharacterEncoding("utf-8");
        resp.setHeader("content-type","text/html;charset=utf-8");

        resp.getWriter().write("你好o~~");
//        resp.getOutputStream().write("你好".getBytes());

    }
}
